package com.tangguangdi.base.core.exception;

import com.tangguangdi.base.common.basic.Result;
import com.tangguangdi.base.common.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 全局异常处理器
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 无参构造器
     */
    public GlobalExceptionHandler(){}

    /**
     * 业务异常处理
     * @param ex 异常信息
     * @return Result
     */
    @ExceptionHandler(BusinessException.class)
    public Result businessError(BusinessException ex) {
        return new Result().setCode(ex.getCode()).setMessage(ex.getMessage());
    }
}
